﻿using B.S.Sterilizationcenter.Domain.zmc;
using B.S.Sterilizationcenter.ErrorCode;
using B.S.Sterilizationcenter.Read.API.Appliaction.Commends.zmc.Outbounds;
using B.S.Sterilizationcenter.Read.API.Dto;
using MediatR;
using SqlSugar;

namespace B.S.Sterilizationcenter.Read.API.Appliaction.CommandHandlers.zmc.Outbounds
{
    public class QueryOutboundorderCommendHandlers : IRequestHandler<QueryOutboundorderCommends, ApiResult<List<OutboundDto>>>
    {

        private readonly ISqlSugarClient db;

        public QueryOutboundorderCommendHandlers(ISqlSugarClient db)
        {
            this.db = db;
        }


        /// <summary>
        /// 查询出库单
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<List<OutboundDto>>> Handle(QueryOutboundorderCommends request, CancellationToken cancellationToken)
        {
            ApiResult<List<OutboundDto>> result = new ApiResult<List<OutboundDto>>();
            result.Code = ApiEnums.查询成功;
            result.Msg = "查询成功";

           /* var list = db.Queryable<Outbound>().ToList();*/
       var list = db.Queryable<Outbound>().LeftJoin<OutboundType>((a, b) => a.OutboundTypeId==b.OutboundTypeId).Select((a,b)=>new OutboundDto
       {
           OutboundId = a.OutboundId,
           OutboundNo = a.OutboundNo,
           OutboundNumber = a.OutboundNumber,
           Outbounddepartment=a.Outbounddepartment,
           AuditDate = a.AuditDate,
           Status = a.Status,
           OutboundTypeId=b.OutboundTypeId,
           OutboundTypeName=b.OutboundTypeName,
       }).ToList();
            result.Data = list;

            return result;
        }
    }
}
